//
// @author				mitchell
// @description		020101.html页面的JS打包文件 注意引用顺序
// @lastmodified		$2010-7 - 15$
$(document).ready(function(){
/*	$("#xy").click(function(){
		if(!$("#xy").attr("checked")){
			$('.enroll-del-a1').attr("class","enroll-del-a-ashy");
			$(".reg").attr("disabled", "true");
		}else{
			$('.enroll-del-a-ashy').attr("class","enroll-del-a1");
			$(".reg").attr("disabled", "");
		}
	});*/
	
	//login
	$(".denglu").click(function(event){
		event.preventDefault();
		var url = $('.fas form').attr("action");
		var email = $(".fas form input:eq(0)").val();
		var password = $(".fas form input:eq(1)").val();
		$.get(url,{ "email" : email,"password" :password }, function(result){
			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			if(result.error == 2){
				alert('登录帐号错误');
				return false;
			}
			if(result.error == 1){
				alert('密码错误');
				return false;
			}
			 window.location.href="index"; 
		},"json");
	});
	
	// 浮动login
	$('.imm a').click(function(event){
		event.preventDefault;
		$(".pop-up").hide();
					   });
	$('.right .login input').click(function(){
		$(".pop-up").show();
	});
	
	//reg submit
	$("#username").keypress( function(e) {
		var key = window.event ? e.keyCode : e.which;
		if(key.toString() == "13"){
			var username = $("#username").val();
			if(!username){
				$(".username").show();
				return false;
			}
			$(".username").hide();
		}
	});
	
	$("#email").keypress( function(e) {
		var key = window.event ? e.keyCode : e.which;
		if(key.toString() == "13"){
			var email = $("#email").val();
			if(!email){
				$(".email").show();
				return false;
			}
			$(".email").hide();
			
		}
	});
	
	$("#password").keypress( function(e) {
		var key = window.event ? e.keyCode : e.which;
		if(key.toString() == "13"){
			var password = $("#password").val();
			if(!password){
				$(".psd").show();
				return false;
			}
			$(".psd").hide();
			
		}
	});
	
	$("#two_password").keypress( function(e) {
		var key = window.event ? e.keyCode : e.which;
		var _this = this;
		if(key.toString() == "13"){
			var two_password = $("#two_password").val();
			if(!two_password){
				$(".repeat_psd").show();
				return false;
			}
			$(".repeat_psd").hide();
		}
	});
	
	
	// reg
	$('#email').blur(function(){
		var email = $.trim($("#email").val());
		if(email == ""){
			$('.email').show();
			$('.email_pic').hide();
			//$('.reg').attr("disabled", "true");
			$(".enroll-del-a1").attr("class","enroll-del-a-ashy");
			$(".enroll-del-a2").attr("class","enroll-del-a2-ashy");
			return false; 
		}else{
			var myreg = /^[a-zA-Z0-9._%-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z]{1,4}$/;
			 if(!myreg.test(email)){
				 $('.email').show();
				 $('.email_pic').hide();
				 //$('.reg').attr("disabled", "true");
				 $(".enroll-del-a1").attr("class","enroll-del-a-ashy");
				 $(".enroll-del-a2").attr("class","enroll-del-a2-ashy");
				// $("#email").focus();
				 return false; 
			 }else{
				 $('.email').hide();
				 $('.email_pic').show();
				 //$('.reg').attr("disabled", "");
				 $(".enroll-del-a-ashy").attr("class","enroll-del-a1");
				 $(".enroll-del-a2-ashy").attr("class","enroll-del-a2");
			 }
		}
		var url = js_context.base_url+"ajax/reg/check_reg";
		var type = $(this).attr("types");
		$.post(url,{"typeid" : email,"type":type},function(result){
			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			var data = result.message;
			if(data){
				$(".c_email").show();
				return false;
			}
			$(".c_email").hide();
		},"json"); 
	});
	
	$('#password').blur(function(){
		var password = $.trim($("#password").val());
		if(password == "" || password.length < 6){
			$('.psd').show();
			$('.password_pic').hide();
			//$('.reg').attr("disabled", "true");
			$(".enroll-del-a1").attr("class","enroll-del-a-ashy");
			$(".enroll-del-a2").attr("class","enroll-del-a2-ashy");
			//setTimeout(function(){$('#password').focus();},0);
			return false;
		}else{
			$('.psd').hide();
			$('.password_pic').show();
			//$('.reg').attr("disabled", "");
			 $(".enroll-del-a-ashy").attr("class","enroll-del-a1");
			 $(".enroll-del-a2-ashy").attr("class","enroll-del-a2");
		}
	});
	
	
	$('#two_password').blur(function(){
		var password = $.trim($("#password").val());
		var repeat_password = $.trim($("#two_password").val());
		if(password == ""){
			$("#two_password").val('');
			//setTimeout(function(){$('#password').focus();},0);
			return false;
		}
		if(repeat_password == "" ||repeat_password.length < 6 || password !=repeat_password){
			//setTimeout(function(){$('#two_password').focus();},0);
			$('.repeat_psd').show();
			$('.two_password_pic').hide();
			//$('.reg').attr("disabled", "true");
			$(".enroll-del-a1").attr("class","enroll-del-a-ashy");
			$(".enroll-del-a2").attr("class","enroll-del-a2-ashy");
			return false;
		}else{
			$('.repeat_psd').hide();
			$('.two_password_pic').show();
			//$('.reg').attr("disabled", "");
			$(".enroll-del-a-ashy").attr("class","enroll-del-a1");
			$(".enroll-del-a2-ashy").attr("class","enroll-del-a2");
		}
		
	});
	//验证用户名是否重复的ajax,未做
	$('#username').blur(function(){
		var username = $.trim($("#username").val());
		if(username == ""){
			$('.username').show();
			$('.username_pic').hide();
			//$('.reg').attr("disabled", "true");
			$(".enroll-del-a1").attr("class","enroll-del-a-ashy");
			$(".enroll-del-a2").attr("class","enroll-del-a2-ashy");
			return false;
		}else{
			$('.username').hide();
			$('.username_pic').show();
			//$('.reg').attr("disabled", "");
			$(".enroll-del-a-ashy").attr("class","enroll-del-a1");
			$(".enroll-del-a2-ashy").attr("class","enroll-del-a2");
		}
		var url = js_context.base_url+"ajax/reg/check_reg";
		var type = $(this).attr("types");
		$.get(url,{"typeid" : username,"type":type},function(result){
			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			var data = result.message;
			if(data){
				$(".c_name").show();
				$(".enroll-del-a1").attr("class","enroll-del-a-ashy");
				$(".enroll-del-a2").attr("class","enroll-del-a2-ashy");
				return false;
			}
			$(".c_name").hide();
			$(".enroll-del-a-ashy").attr("class","enroll-del-a1");
			$(".enroll-del-a2-ashy").attr("class","enroll-del-a2");
		},"json"); 
	});
	
	$('#tel').blur(function(){
		var tel = $.trim($(this).val());
		//var type = $(this).attr('types');
		if(tel == ""){
			$('.tel').show();
			$('.tel_pic').hide();
			//$('.reg').attr("disabled", "true");
			return false;
		}
		var myreg = /^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$/;
		//var myreg = /^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/;
		if( !myreg.test(tel)){
			$('.tel').show();
			$('.tel_pic').hide();
			//$('.reg').attr("disabled", "true");
			 return false; 
		}
		/*
		var url = js_context.base_url+"ajax/reg/check_reg";
		$.get(url, {'typeid' : tel,'type' : type}, function(result){
			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			var data = result.message;
			if(data){
				$('.tel').html('手机号码已 被注册').show();
				return false;
			}
			$('.tel').html('请注意手机号码格式').hide();
			$('.tel_pic').show();
			//$('.reg').attr("disabled", "");
		},"json");
		*/
	});
	
	//被省略了
	$('#residence').blur(function(){
		var residence = $.trim($("#residence").val());
		//var area = $(".areainfo").find("span").html();
		var area =$("#areaArr").val();
		if(residence.indexOf(area) == 0){
			$(".residence").hide();
			return false;
		}else{
			$(".residence").show();
			return false;
		}
	});
	
	$(".reg").click(function(event){
		event.preventDefault();
		var url = js_context.base_url+"userController/reg";//地址
		var email = $.trim($("#email").val()); 
		var password = $.trim($("#password").val());
		var two_password = $.trim($("#two_password").val());
		var username = $.trim($("#username").val()); 
		var cid = $(".cityinfo span").attr("cid"); //cid和aid是写在页面jsp里的,但是没有提取过来用
		var aid = $(".areainfo span").attr("aid");
		var area = document.getElementById("areaArr").value;
		var residence = $.trim($("#residence").val()); 
		var taid = $(".tradlist span").attr("taid");
		var tel = $.trim($("#tel").val());
		$.post(url,{ "mail":email,"password":password,"pname":username,"city":'长春',//city默认长春了
					"area":area,"tel":tel},function(r){//""里的字段对应映射类的成员名
					var obj = r;
					if (obj.success) {
						window.location.href = js_context.base_url;
					}
					$.messager.show({
						title : '提示',
						msg : obj.msg
					});
		},"json");
	});
	
	//cirylist
	$(".cityinfo").mouseover(function(event){
		event.preventDefault();
		var _this = this;
		$(".city_list").show();
		$(_this).mouseleave(function(event){
			event.preventDefault();
			$(".city_list").hide();
		});
		$(".city_info").click(function(event){
			event.preventDefault();
			var city_this = this;
			var cid = $(city_this).attr("cid");
			var html = $(city_this).html();
			$(".city_list").hide();
			$(_this).find("span").attr("cid",cid);
			$(_this).find("span").html(html);
		});
	});
	
	//arealist 地址信息应该是检索出来的,也没做
	$(".areainfo").mouseover(function(event){
		event.preventDefault();
		var _this = this;
		$(".area_list").show();
		$(".areainfo").mouseleave(function(event){
			event.preventDefault();
			$(".area_list").hide();
		});
	});
	
	$(".area_info").click(function(event){
		event.preventDefault();
		var area_this = this;
		var url = js_context.base_url+"ajax/search/trading";
		var aid = $(area_this).attr("aid");
		var html = $(area_this).html();
		$(".area_list").hide();
		$(".area_load").show();
		$(".areainfo").find("span").attr("aid",aid);
		$(".areainfo").find("span").html(html);
		$(".hid_aid").val(aid);
		$(".tradingArr").hide();
		$("#areaArr").val(html);
		if(aid == $(".area_"+aid).attr('aid')){
			$(".sus,.area_"+aid).show();
			$(".area_load").hide();
			return false;
		}
		//显示选择的区域名alert(document.getElementById("areaArr").value);
		/*$.get(url,{"aid" : aid},function(result){
			$(".area_load").hide();
			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			var data = result.message;
			if(!data){
				alert('查询失败');
				return false;
			}
			var html = ""; 
				html += "<div class='tradingArr area_"+aid+"' aid='"+aid+"'>"
				html +=	result.message;
				html += "</div>";
			$(".sus").append(html).show();

			//somolist
			$(".trad_info_"+result.aid).click(function(event){
				event.preventDefault();
				var trad_this = this;
				var url = js_context.base_url+"ajax/search/somoarr";
				var taid = $(trad_this).attr("taid");
				var html = $(trad_this).html().substr(0,5);
				$(".somolist").hide();
				$(".trading_load").show();
				//$("#trading_"+aid).find("span").attr("taid",taid);
				$(".tradArr").find("span").html(html);
				$(".hid_taid").val(taid);
				if(taid == $(".trading_"+taid).attr('taid')){
					$(".trading_"+taid).show();
					$(".trading_load").hide();
					return false;
				}
				$.get(url,{"taid" : taid},function(result){
					$(".trading_load,.sus").hide();
					if(result.success == false){
						alert('通讯失败');
						return false;
					}
					var data = result.message;
					if(!data){
						alert('查询失败');
						return false;
					}
					var html = '';
						html+= '<div taid="'+result.taid+'" class="somolist trading_'+result.taid+'">';
					for(var i=0;i<data.length;i++){
						html += '<span><input type="radio" name="somoid" value="'+data[i].somoid+'" somoid="';
						html += data[i].somoid;
						html += '"/><label>';
						html += data[i].name.substr(0,4);
						html += '</label></span>';
					}
						
					if(data == ''){
						html +='<div taid="'+result.taid+'" class="somolist trading_'+result.taid+'"><font style="color:red;">该商圈下没有写字楼数据！</font></div>';
					}
					html += '</div>';
					$(".somoArr").append(html).show();
				},"json");  
			});
			
		},"json")*/;
	});
	//tradingarea
	$(".tradArr").mouseover(function(event){
		event.preventDefault();
		var _this = this;
		$(".sus").show();
	});
	$(".tradArr").mouseleave(function(event){
		event.preventDefault();
		$(".sus").hide();
	});
	//somolist
	var aid = js_context.aid;
	$(".trad_info_"+aid).click(function(event){
		event.preventDefault();
		var trad_this = this;
		var url = js_context.base_url+"ajax/search/somoarr";
		var taid = $(trad_this).attr("taid");
		var html = $(trad_this).html().substr(0,5);;
		$(".somolist").hide();
		$(".tradArr").find("span").html(html);
		$(".hid_taid").val(taid);
		$(".trading_load").show();
		if(taid == $(".trading_"+taid).attr('taid')){
			$(".trading_"+taid).show();
			$(".trading_load,.sus").hide();
			return false;
		}
		$.get(url,{"taid" : taid},function(result){
			$(".trading_load,.sus").hide();
			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			var data = result.message;
			if(!data){
				alert('查询失败');
				return false;
			}
			var html = '';
				html+= '<div taid="'+result.taid+'" class="somolist trading_'+result.taid+'">';
			for(var i=0;i<data.length;i++){
				html += '<span><input type="radio" name="somoid" value="'+data[i].somoid+'" somoid="';
				html += data[i].somoid;
				html += '"/><label>';
				html += data[i].name.substr(0,4);
				html += '</label></span>';
			}
				
			if(data == ''){
				html +='<div taid="'+result.taid+'" class="somolist trading_'+result.taid+'"><font style="color:red;">该商圈下没有写字楼数据！</font></div>';
			}
			html += '</div>';
			$(".somoArr").append(html).show();
		},"json");  
	});
});
